from typing import Any, Hashable

class VE_Data:
    """ Base class for game data storage """

class VE_HashMapStorage(VE_Data, dict):
    """Dict-like storage, support nested get / set
    
    Usage::

        storage = VE_HashMapStorage() # Initialize
    
        storage["is_initialized"] = True
        storage["time", "sec"] = 2
        storage["time", "min"] = 3
        print(storage) # {'is_initialized': True, 'time': {'sec': 2, 'min': 3}}
    
    """
    
    def __getitem__(self, __key: Hashable | tuple[Hashable, ...]) -> Any:
        if not isinstance(__key, tuple):
            return dict.__getitem__(self, __key)
        
        layer = self
        key = list(__key).copy()
        while key:
            k = key.pop(0)
            
            if not key:
                return layer.get(k)
            
            if layer.get(k) is None:
                return None
                
            layer = dict.__getitem__(layer, k)

    def __setitem__(self, __key: Hashable | tuple[Hashable, ...], __value: Any) -> None:
        if not isinstance(__key, tuple):
            dict.__setitem__(self, __key, __value)
            return
    
        layer = self
        key = list(__key).copy()
        while key:
            k = key.pop(0)
            
            if not key:
                dict.__setitem__(layer, k, __value)
                return
            
            if layer.get(k) is None:
                dict.__setitem__(layer, k, {})
            layer = dict.__getitem__(layer, k)


class VE_SequenceStorage(VE_Data, list): ...
